//package com.ls.knowledge.springAi.controller;
//
//import org.springframework.ai.chat.client.ChatClient;
//import org.springframework.ai.chat.client.advisor.vectorstore.QuestionAnswerAdvisor;
//import org.springframework.ai.document.Document;
//import org.springframework.ai.reader.tika.TikaDocumentReader;
//import org.springframework.ai.transformer.splitter.TokenTextSplitter;
//import org.springframework.ai.vectorstore.SimpleVectorStore;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.core.io.ClassPathResource;
//import org.springframework.core.io.Resource;
//import org.springframework.http.MediaType;
//import org.springframework.stereotype.Controller;
//import org.springframework.web.bind.annotation.GetMapping;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RestController;
//import reactor.core.publisher.Flux;
//
//import java.io.File;
//import java.io.IOException;
//import java.util.List;
//
///**
// * @BelongsProject: knowledge
// * @BelongsPackage: com.ls.knowledge.springAi.controller
// * @Author: lishun
// * @CreateTime: 2025-07-10  23:06
// * @Description:
// * @Version: 1.0
// */
//@RestController
//public class RagTestController {
//
//    @Autowired
//    private OllamaChatModel chatModel;
//
//    @Autowired
//    private OllamaEmbeddingModel ollamaEmbeddingModel;
//
//    @GetMapping(name = "ragTest",produces = MediaType.TEXT_EVENT_STREAM_VALUE)
//    public String ragTest() throws IOException {
//        // 启动向量存储
//        SimpleVectorStore vectorStore = SimpleVectorStore.builder(ollamaEmbeddingModel).build();
//
//        // 读取 classpath 下的文件
//        Resource resource = new ClassPathResource("doc/doc1.md");
//        TikaDocumentReader tikaDocumentReader = new TikaDocumentReader(resource);
//
//        // 文本切分
//        List<Document> documents = tikaDocumentReader.get();
//        TokenTextSplitter splitter = new TokenTextSplitter();
//        List<Document> documentList = splitter.apply(documents);
//
//        // 加入向量库
//        vectorStore.add(documentList);
//
//        // 问答逻辑
//        return ChatClient.builder(chatModel)
//                .build().prompt()
//                .advisors(new QuestionAnswerAdvisor(vectorStore))
//                .user("二分查找算法怎么写？")
//                .call().content();
//    }
//
//}
